<template>
	<div class="control-content">
		<div class="control-content--joystick">
			<div class="joystick--ellipse">
				<div class="joystick--ellipse1"></div>
				<div class="joystick--ellipse2"></div>
			</div>
			<div class="joystick--up" @mousedown="setPstMousedown(VideoControlEnum.UP)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--right-up" @mousedown="setPstMousedown(VideoControlEnum.RIGHT_UP)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--right" @mousedown="setPstMousedown(VideoControlEnum.RIGHT)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--right-down" @mousedown="setPstMousedown(VideoControlEnum.RIGHT_DOWN)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--down" @mousedown="setPstMousedown(VideoControlEnum.DOWN)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--left-down" @mousedown="setPstMousedown(VideoControlEnum.LEFT_DOWN)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--left" @mousedown="setPstMousedown(VideoControlEnum.LEFT)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
			<div class="joystick--left-top" @mousedown="setPstMousedown(VideoControlEnum.LEFT_UP)" @mouseup="setPstMouseup(VideoControlEnum.STOP)">
				<img class="img" src="../../../assets/direction.png" />
			</div>
		</div>
		<el-row>
			<el-col :span="12">
				<div class="p-r-8 control--label">控制速度</div>
				<el-input-number
					v-model="speed"
					:step="1"
					:min="1"
					:max="255"
					placeholder="控制速度"
					class="custom-input-number m-t-16"
					size="small"
				></el-input-number>
			</el-col>
			<el-col :span="12">
				<div class="button-cell">
					<div class="button-cell--item">
						<el-button
							type="primary"
							size="small"
							@mousedown="setPstMousedown(VideoControlEnum.ZOOM_IN)"
							@mouseup="setPstMouseup(VideoControlEnum.STOP)"
							>+</el-button
						>
						<div class="button-cell--item__title">变倍</div>
						<el-button
							type="primary"
							size="small"
							@mousedown="setPstMousedown(VideoControlEnum.ZOOM_OUT)"
							@mouseup="setPstMouseup(VideoControlEnum.STOP)"
							>-</el-button
						>
					</div>
					<div class="button-cell--item">
						<el-button
							type="primary"
							size="small"
							@mousedown="setPstMousedown(VideoControlEnum.FOCUS_NEAR)"
							@mouseup="setPstMouseup(VideoControlEnum.OTHER_STOP)"
							>+</el-button
						>
						<div class="button-cell--item__title">聚焦</div>
						<el-button
							type="primary"
							size="small"
							@mousedown="setPstMousedown(VideoControlEnum.FOCUS_FAR)"
							@mouseup="setPstMouseup(VideoControlEnum.OTHER_STOP)"
							>-</el-button
						>
					</div>
					<div class="button-cell--item">
						<el-button
							type="primary"
							size="small"
							@mousedown="setPstMousedown(VideoControlEnum.IRIS_ENLARGE)"
							@mouseup="setPstMouseup(VideoControlEnum.OTHER_STOP)"
							>+</el-button
						>
						<div class="button-cell--item__title">光圈</div>
						<el-button
							type="primary"
							size="small"
							@mousedown="setPstMousedown(VideoControlEnum.IRIS_REDUCE)"
							@mouseup="setPstMouseup(VideoControlEnum.OTHER_STOP)"
							>-</el-button
						>
					</div>
				</div>
			</el-col>
		</el-row>
		<div></div>
	</div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { usePstControlApi, useZfaControlApi } from '../../../api/contols'
import { VideoControlEnum } from '../../../enum'

const props = defineProps({
	liveOptions: {
		type: Object,
		default: () => ({}),
		required: true
	}
})

const speed = ref<number>(129)

// 鼠标按键按下
const setPstMousedown = (controlType: string) => {
	const direction: any = [
		VideoControlEnum.UP,
		VideoControlEnum.RIGHT_UP,
		VideoControlEnum.RIGHT,
		VideoControlEnum.RIGHT_DOWN,
		VideoControlEnum.DOWN,
		VideoControlEnum.LEFT_DOWN,
		VideoControlEnum.LEFT,
		VideoControlEnum.LEFT_UP,
		VideoControlEnum.ZOOM_IN,
		VideoControlEnum.ZOOM_OUT
	]

	console.log(props.liveOptions, 'props.liveOptions')

	if (props.liveOptions.serial) {
		if (direction.includes(controlType)) {
			// 转台控制-方位控制 变倍
			usePstControlApi({
				...props.liveOptions,
				command: controlType,
				speed: speed.value
			})
		} else {
			// 转台控制-|聚焦|光圈
			useZfaControlApi({
				...props.liveOptions,
				command: controlType,
				speed: speed.value
			})
		}
	}
}

// 鼠标按键抬起
const setPstMouseup = (controlType: string) => {
	const direction: any = [VideoControlEnum.STOP]

	if (props.liveOptions.serial) {
		if (direction.includes(controlType)) {
			// 转台控制-方位控制  变倍
			usePstControlApi({
				...props.liveOptions,
				command: VideoControlEnum.STOP,
				speed: speed.value
			})
		} else {
			// 转台控制-|聚焦|光圈
			useZfaControlApi({
				...props.liveOptions,
				command: VideoControlEnum.STOP,
				speed: speed.value
			})
		}
	}
}
</script>
<style lang="scss" scoped>
.custom-flex {
	display: flex;
	align-items: center;
}

.custom-input-number {
	width: 120px;
}

.m-t-16 {
	margin-top: 16px;
}

.p-r-8 {
	padding-right: 8px;
}

.control--label {
	margin-top: 20px;
	text-align: center;
}
.control-content {
	color: var(--el-text-color-primary);
}

.control-content--joystick {
	position: relative;
	width: 160px;
	height: 160px;
	margin: 0 auto;

	.img {
		width: 40px;
		height: 40px;
		cursor: pointer;
	}

	.joystick--ellipse {
		border-width: 0px;
		position: absolute;
		left: 30px;
		top: 30px;
		width: 100px;
		height: 100px;
		display: flex;

		.joystick--ellipse1 {
			width: 100px;
			height: 100px;
			background-color: #e4e4e4;
			border-radius: 5000%;
			position: absolute;
		}

		.joystick--ellipse2 {
			width: 70px;
			height: 70px;
			background-color: #7abfff;
			position: absolute;
			border-radius: 5000%;
			z-index: 1;
			left: 14px;
			top: 14px;
		}
	}

	.joystick--up {
		border-width: 0px;
		position: absolute;
		left: 70px;
		top: -10px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(90deg);
		opacity: 0.5;
	}

	.joystick--right-up {
		border-width: 0px;
		position: absolute;
		right: 5px;
		top: 17px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(135deg);
		opacity: 0.5;
	}

	.joystick--right {
		border-width: 0px;
		position: absolute;
		right: -10px;
		top: 70px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(180deg);
		opacity: 0.5;
	}

	.joystick--right-down {
		border-width: 0px;
		position: absolute;
		right: 16px;
		bottom: 10px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(225deg);
		opacity: 0.5;
	}

	.joystick--down {
		border-width: 0px;
		position: absolute;
		left: 60px;
		bottom: -10px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(270deg);
		opacity: 0.5;
	}

	.joystick--left-down {
		border-width: 0px;
		position: absolute;
		left: 10px;
		bottom: 14px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(315deg);
		opacity: 0.5;
	}

	.joystick--left {
		border-width: 0px;
		position: absolute;
		left: -10px;
		top: 60px;
		width: 30px;
		height: 30px;
		display: flex;
		opacity: 0.5;
	}

	.joystick--left-top {
		border-width: 0px;
		position: absolute;
		left: 9px;
		top: 9px;
		width: 30px;
		height: 30px;
		display: flex;
		transform: rotate(30deg);
		opacity: 0.5;
	}
}

.button-cell {
	height: 120px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: space-evenly;
	.button-cell--item {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		// padding: 4px;

		.button-cell--item__title {
			font-size: 12px;
		}
	}
}

.control-form {
	color: var(--el-text-color-primary);
	.control-form--title {
		font-size: 12px;
		margin: 8px 0;
	}
}
</style>
